/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lucene.Analyzers;

import java.io.IOException;
import java.util.Set;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;

public class PositionStopFilter extends TokenFilter{
    private Set stopWords;
    
    public PositionStopFilter (TokenStream in, Set stopWords) {
        super(in);
        this.stopWords = stopWords;
    }

    @Override
    public final Token next() throws IOException {
        int increment = 0;
        for (Token token = input.next(); token != null; token = input.next()) {
            if (!stopWords.contains(token.termText())) {
                token.setPositionIncrement(token.getPositionIncrement() + increment);
                return token;
            }
        increment++;
        }
        return null;
    }
}
